package com.example.wjh.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import com.example.wjh.entity.Player;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Map;


@Mapper
public interface PlayerMapper extends BaseMapper<Player> {
    @Select("select * from player where username=#{username} and password=#{password}" )
    Player login(Player player);

    @Select("<script> " +
            "SELECT * FROM player " +
            "<where> " +
            "<if test='name != null'> AND name LIKE CONCAT('%', #{name}, '%')</if> " +
            "<if test='username != null'> AND username LIKE CONCAT('%', #{username}, '%')</if> " +
            "<if test='position != null'> AND position LIKE CONCAT('%', #{position}, '%')</if> " +
            "</where> " +
            "</script>")
    List<Player> searchPlayer(
            @Param("name") String name,
            @Param("username") String username,
            @Param("position") String position);

    @Select("SELECT position as 司职位置, COUNT(*) as 人数 FROM player GROUP BY position")
    List<Map<String, Object>> countPlayersByPosition();
}
